home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Z80ppc 160.sit / Z80ppc 160 / Z80.reference.c < prev    next >
Text File  |  1995-04-15  |  3KB  |  109 lines

  1. /*    Z80 reference emulator
  2.     Copyright (C) 1995 G.Woigk
  3.     
  4.     This file is part of Mac Spectacle and it is free software
  5.     See application.c for details
  6.             
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  10.  
  11.     based on fMSX; Copyright (C) Marat Fayzullin 1994,1995
  12.  
  13.     12.Apr.95     Started work on this file                    KIO !
  14. */
  15.  
  16.  
  17. #include    "kio.h"
  18. #include    "z80.reference.h"
  19. #include    "Z80.ppc.macros"
  20.  
  21.  
  22. // -----    Flags after logic operations -------------------------------------
  23. Char        zlog_flags[256];    // convert  A -> Z80-flags with V=parity, S, Z, and C=0
  24.  
  25. // -----    The Z80 RAM ------------------------------------------------------
  26. Char        *CORE = nil;
  27.  
  28. // -----    The Z80 registers on entry and exit of Z80() ---------------------
  29. regs        zreg;
  30.  
  31.  
  32. // -----    Dummy procs ------------------------------------------------------
  33. No_Output(Short A, Char N) {}
  34. Dont_Write(Short A, Char N) {}
  35.  
  36.  
  37. // -----    The Z80 Reference Engine ----------------------------------------------
  38.  
  39. short Z80_Ref()
  40. {    register Char    c;                // general purpose byte register
  41.     register Short    w;                // general purpose word register
  42.     register Short    wm;                // help register for macro internal use
  43.     register pair    *izp;            // address ix or iy
  44.     define_r;                        // define r if exact r register emulation
  45.  
  46. #define    loop        goto nxtcmnd
  47.  
  48.  
  49. // check zreg.WUFF to see, whether an NMI or IRPT is pending:
  50. // also called after ei processing!
  51. check_wuff:
  52.     if (zreg.WUFF)
  53.     {    if (zreg.WUFF&0x80)                    // NMI:  0x0066; 11 T cycles
  54.         {    do_info_nmi;
  55.             zreg.WUFF&=0x7F;
  56.             zreg.IFF2=zreg.IFF1;
  57.             zreg.IFF1=disabled;
  58.             push(pc);
  59.             pc = 0x0066;
  60.             more(11);
  61.             loop;
  62.         }
  63.         if (zreg.IFF1==enabled)                // interrupts enabled?
  64.         {    do_info_irpt;
  65.             zreg.WUFF--;                    // clear interrupt request
  66.             zreg.IFF1=zreg.IFF2=disabled;    // disable iff1 & iff2
  67.             switch (zreg.IM)
  68.             {
  69.             case 0:            // mode 0: read instr; 1 T cycle + normal instr timing
  70.             //    if (zreg.irptcmd==RST38)
  71.             //    {    push(pc);
  72.             //        pc = 0x0038;
  73.             //        more(12);        // RST==11T + 1T
  74.             //        loop;
  75.             //    };
  76.             //    exit(irpt_error);    // not supported instruction read in irpt ackn cycle
  77.             case 1:            // mode 1:  rst 56; 13 T cycles
  78.                 push(pc);
  79.                 pc = 0x0038;
  80.                 more(13);
  81.                 loop;
  82.             case 2:            // mode2:  jmp via table; 19 T cycles
  83.                 push(pc);
  84.                 w = *(Short*)&zreg.I;        // read both: zreg.I & zreg.irptcmd !!!
  85.                 pc = ((Short)peek(w+1)<<8) + peek(w);
  86.                 more(19);
  87.                 loop;
  88.             default:
  89.                 exit(irpt_error);
  90.             };
  91.         };
  92.     };
  93.  
  94. // -----    THE MAIN INSTRUCTION DISPATCHER --------------------------------
  95.  
  96. nxtcmnd:
  97.     if ((cc-=4)>=0)            // -4 T cycles for most common instructions
  98.     {    increment_r;
  99.         switch(n)
  100.         {
  101. #include "Codes.c"
  102.         }
  103.         loop;
  104.     }
  105.     cc+=4;
  106.     return(ok);
  107. }
  108.  
  109.